<template>
  <section>

    <van-row>
      <van-col v-show="isLogin" span="8" col="8">{{username}}</van-col>
      <van-col span="8" col="8">
        <van-button v-show="isLogin" @click="logout">退出登录</van-button>
        <van-button v-show="!isLogin" @click="openWin('./login.html')">登录</van-button>
      </van-col>

    </van-row>
  </section>
</template>

<script>
import common from "../../../../util/index";
import {Button, Field, CellGroup, Cell, Row, Col, Toast} from "vant/es";

export default {

  components: {
    [Button.name]: Button,
    [Row.name]: Row,
    [Col.name]: Col,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
  },

  computed: {},

  data() {
    return {
      username: "",
      isLogin: 0,
    };
  },

  mounted() {
    window.apiready = () => {
      this.isLogin = parseInt(this.getPrefsSync("local.isLogin")) || 0;
      this.username = this.getPrefsSync("local.username") || "";
    };
  },
  methods: {
    logout() {

      this.setPrefs("local.isLogin", 0);
      this.removePrefs("ouath2.client_id");
      this.removePrefs("ouath2.client_secret");
      this.removePrefs("ouath2.grant_types");
      this.removePrefs("ouath2.redirect_uri");
      this.removePrefs("ouath2.token_type");
      this.removePrefs("ouath2.express_in");
      this.removePrefs("ouath2.access_token");
      this.removePrefs("ouath2.refresh_token");
      this.removePrefs("ouath2.express_at");

      console.log(api.windows());

      this.closeToWin("main");
      // this.reloadFrame();
    },
    ...common.methods,
  },
};
</script>

<style>

</style>
